<template>
  <div class="container">
    <!-- 标题定制区域 -->
    <el-row>
      <el-col :span="9" :push="4">
        <div class="diy-container">
          <img src="../../assets/img/top1.png" alt="">
          <div class="one">
            <p>迎新杯--全新赛制</p>
          </div>
          <div class="two">
            <p>2023年全新赛制狂欢来袭</p>
            <p>全场新积分赛制<span>小组淘汰制</span><span>诚挚邀请</span></p>
          </div>
        </div>
      </el-col>
      <el-col :span="10" :push="4">
        <div class="diy-container2">
          <p>比赛报名流程：</p>
          <p>报名费: 50/人(报名费无退) 败方支付台费(不可用会员卡)</p>
          <p>比赛名额: 24人<span>比赛时间: 01.16</span></p>
          <p>比赛报名方式: 15382942008(微信同步), 也可到店前台报名登记噢!</p>
          <p>冠军: 1288元现金+奖杯+证书</p>
          <p>季军: 888元现金+奖杯+证书</p>
          <p>亚军: 588元现金+奖杯+证书</p>
          <p>殿军: 200元充值卡</p>
          <p>本次比赛最终解释权归清8台球俱乐部所有</p>
        </div>
      </el-col>
    </el-row>
    <!-- 比赛数据 -->
    <el-row class="match-data">
        <el-col :span="7" v-for="(item, key) in allGameData" :key="key">
          <div>
            <div class="table-header">{{ item.groupName }}</div>
            <el-table size="small" :data="item.data" style="width: 100%" stripe border>
              <el-table-column show-overflow-tooltip prop="teamMember" label="队员名称" align="center" />
              <el-table-column show-overflow-tooltip prop="teamName" label="所属小组" align="center" />
              <el-table-column show-overflow-tooltip prop="teamMemberSessions" label="场次" align="center" />
              <el-table-column show-overflow-tooltip prop="teamMemberPoints" label="积分" align="center" />
            </el-table>
          </div>
        </el-col>
    </el-row>
  </div>
</template>

<script>
import { getItem } from '../../../utils/storage'
export default {
  name: 'integralDisplay',
  data() {
    return {
      allGameData: []
    }
  },
  mounted() {
    // 三秒刷新一次数据
    this.getAllGameData()
    let timer = setInterval(() => {
      this.getAllGameData()
    }, 3000)

    // 离开页面时销毁定时器
    this.$once('hook:beforeDestroy', () => {
      clearInterval(timer);
      timer = null;
    })
  },
  methods: {
    // 获取所有比赛数据
    getAllGameData() {
      this.allGameData = []
      // 过滤出所有队伍名字
      const temp = getItem('personData')
      const allGroupData = temp && [...new Set(temp.map(item => item.groupValue))]
      // 判断是否有队伍
      if (allGroupData && allGroupData.length > 0) {
        for(let i=0;i<allGroupData.length;i++){
          // 循环筛选出每个队伍的数据、格式化数据、排序数据(从高到低)
          this.allGameData.push({
            'groupName': allGroupData[i],
            // 队员积分排序
            'data': temp.filter(item => item.groupValue === allGroupData[i]).map(item => {
              return {
                teamMember: item.label,
                teamName: item.groupValue,
                teamMemberSessions: item.currentSessions,
                teamMemberPoints: item.currentScore
              }
            }).sort((a, b) => b.teamMemberPoints - a.teamMemberPoints)
          })
        }
        // 队伍字母排序
        this.allGameData = this.allGameData && this.allGameData.sort((a, b) => {
          if (a.groupName.slice(0,1) < b.groupName.slice(0,1)) { return -1; }
          if (a.groupName.slice(0,1) > b.groupName.slice(0,1)) { return 1; }
          return 0;
        }) || []
      }
    }
  }
}
</script>

<style lang="scss">
</style>

<style lang="scss" scoped>
  .container {
    overflow: auto;
    width: 100vw;
    height: 100%;
    padding: 0px 50px 50px;
    background-image: url('../../assets/img/bg2.jpg');
    background-position: center center;
    .diy-container {
      text-align: center;
      margin: 30px 0 20px;
      border-radius: 10px;
      img {
        width: 285px;
      }
      .one {
        width: 491px;
        height: 65px;
        margin: 10px auto 0;
        background-color: #ad422b;
        border-radius: 10px;
        font-size:50px;
        color:white;
        text-shadow:2px 3px 1px #151515;
        p {
          margin: 0;
          padding: 0;
          &:first-child {
            line-height: 65px;
          }
        }
      }
      .two {
        p {
          margin: 0;
          padding: 0;
          &:first-child {
            color: #ffffff;
            font-weight: bold;
            font-size: 27px;
            letter-spacing: 5px;
            margin: 5px 0;
          }
          &:last-child {
            font-size: 18px;
            color: white;
          }
          span {
            margin-left:20px;
          }
        }
      }
    }
    .diy-container2 {
      margin-top: 10px;
      padding-top: 28px;
      padding-left: 30px;
      p {
        margin: 0;
        padding: 0;
        padding-bottom: 8px;
        color: white;
        font-size: 14px;
      }
    }
    .table-header {
      padding: 10px;
      border: 1px solid #EBEEF5;
      border-bottom: none;
      border-top-left-radius: 10px;
      border-top-right-radius: 10px;
      background-color: white;
      text-align: center;
      font-size: 25px;
      font-weight: bold;
      color: #646464;
    }
    ::v-deep .el-table .el-table__header-wrapper .el-table__header {
      font-size: 18px;
      thead {
        color: #6a6a6a !important;
      }
    }
    ::v-deep .el-table .el-table__body-wrapper .el-table__row{
      font-size: 13px;
      font-weight: bold;
    }
    .match-data {
      display: flex;
      flex-direction: row;
      width: 100%;
      flex-wrap: wrap;
      justify-content: center;
      ::v-deep .el-table {
        border-bottom-left-radius: 10px;
        border-bottom-right-radius: 10px;
      }
      ::v-deep .el-col {
        margin-right: 83px;
        // 每三行第三个
        &:nth-child(3n+3) {
          margin-right: 0;
        }
        // 3的倍数
        &:nth-child(1),
        &:nth-child(2),
        &:nth-child(3) {
          margin-bottom: 50px;
        }
      }
    }
  }
  .container::-webkit-scrollbar {
    display:none;
  }
</style>
